/* * Exercise Week 4: An exercise in the concept of packages, operators, conditions and String handling. 
 * In this program you have to interactively ask the user to enter values in degree 
 * Celsius or degree Fahrenheit and give the conversion from one another. 
 * Ask user to enter the value followed by character 'C' for Celsius and 'F' for Fahrenheit. */

package pack_Doris;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//Main method
public class Doris {

	public static void main(String[] args) {

		try {
			// Prompt user to key in value of temperature for conversion
			System.out.print("Please enter the temperature for conversion: ");
			BufferedReader in = new BufferedReader(new InputStreamReader(
					System.in));

			// Read user input string and check the length of string
			String temp = in.readLine();
			int length;
			length = temp.length();

			// Extract the last character of input either c, C or f,F
			String newtemp = temp.substring(0, length - 1);
			String ForC = temp.substring(length - 1);

			// Convert numerical part of string to integer
			int value = Integer.parseInt(newtemp);
//			int value = Integer.parseInt("newtemp");
			int temperature;

			// Temperature conversion to Celsius
			if (ForC.equals("F")||ForC.equals("f")) {
				temperature = (value - 32) * 5 / 9;
				System.out.println("The temperature in Celsius is "
						+ temperature + "C");

			} else if (ForC.equals("C")||ForC.equals("c")) {
				temperature = value * 9 / 5 + 32 ;
				System.out.println("The temperature in Fahrenheit is "
						+ temperature + "F");

			// Error message if user key in other data other than the specified format
			} else {
				System.out
						.println("Invalid input! Please enter a valid numerical value ending either c, C, f or F");
			}
		} catch (IOException e) {
			System.out
					.println("Invalid input! Please enter a valid numerical value ending either c, C, f or F");

		} catch (NumberFormatException e) {
			System.err.println(e.getMessage());
			System.out
					.println("Invalid input! Please enter a valid numerical value ending either c, C, f or F");
		}
	}



	public static String sayHello(){

	  return "Hello!!!";

	}


	public int getdouble(int num){
	 
	  return num*2;

	}

}//End of program
